package com.rederxu.tools;
import com.rederxu.farmer.R;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;

/**
 * @ClassName: ImageUtil
 * @Description: 图片管理类
 * @author wangjiangbo
 * @date 2015-5-7 上午10:40:02
 */
public class ImageUtil {

	private static final String DOWNLOAD_IMAGE_EXTENSION = ".jpg";

	private static final String UPDATE_USERICON_EXTENSION = ".tmp";

	/**
	 * 通知系统全屏扫描
	 * @param context
	 */
	public static final void allScanMedia(Context context) {
		context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
	}

	/**
	 * 扫描文件
	 * @param context
	 * @param file
	 */
	public static void fileScanMedia(Context context, String file) {
		Uri data = Uri.parse("file://" + file);
		context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
	}
	
	//=====================下面是timeline和详情图片尺寸计算=====================

	/** 图片宽度*/
	private static int TIMELINE_LARGE_IMAGE_CONTAINER_WIDTH;
	
	/** 详情图片宽度*/
	private static int DETAILS_IMAGE_CONTAINER_WIDTH;

	/** 图片最大高度*/
	private static int TIMELINE_MAX_IMAGE_CONTAINER_HEIGHT;

	/** 图片margin值, 根据ui计算出来，dp值*/
	private static final int TIMELINE_IMAGE_MARGIN_SPACE = 22;
	/** 详情页图片margin值*/
	private static int TIMELINE_IMAGE_DETAILS_MARGIN_SPACE = 0;

	/**
	 * 获得首页图片宽度
	 * <br>高度根据图片宽高比计算
	 * @return
	 */
	public static int getTimeLineWidth(Context context) {
		if (TIMELINE_LARGE_IMAGE_CONTAINER_WIDTH == 0) {
			TIMELINE_LARGE_IMAGE_CONTAINER_WIDTH = DisplayUtils.getScreenWidth(context)
					- DisplayUtils.dipToPx(context, TIMELINE_IMAGE_MARGIN_SPACE);
		}
		return TIMELINE_LARGE_IMAGE_CONTAINER_WIDTH;
	}

	/**
	 * 帖子详情图片宽度
	 * <br>高度根据图片宽高比计算
	 * @return
	 */
	public static int getDatailsImageWidth(Context context) {
		if (DETAILS_IMAGE_CONTAINER_WIDTH == 0) {
			if (TIMELINE_IMAGE_DETAILS_MARGIN_SPACE == 0) {
				TIMELINE_IMAGE_DETAILS_MARGIN_SPACE = context.getResources()
						.getDimensionPixelSize(R.dimen.details_image_pading) * 2;
			}
			DETAILS_IMAGE_CONTAINER_WIDTH = DisplayUtils.getScreenWidth(context)
					- TIMELINE_IMAGE_DETAILS_MARGIN_SPACE;
		}
		return DETAILS_IMAGE_CONTAINER_WIDTH;
	}

}